
//defination Rectangle class



#include "Rectangle.h"

Rectangle::Rectangle(){


   x1=y1=0;
   x2=y2=0;
   x3=y3=0;
   x4=y4=0;
}


Rectangle::Rectangle(const MyDisplay &another):Line(another){

   x1=y1=0;
   x2=y2=0;
   x3=y3=0;
   x4=y4=0;


}

Rectangle::Rectangle(const Matrix &R){


   x1 =(int) R[0][0];
   y1 =(int) R[0][1];
   
   x2 =(int) R[1][0];
   y2 =(int) R[1][1];
   
   x3 =(int) R[2][0];
   y3 =(int) R[2][1];

   x4 =(int) R[3][0];
   y4 =(int) R[3][1];
  
}


Rectangle::Rectangle(const char *fileName,const MyDisplay &another):Line(another){

  
      ifstream in(fileName);

      	int tempx1,tempy1,d;
	if(!in)
	{
	    cout <<"\n unable to open file : " <<fileName;
	     return;	
	}
	
	//out <<numRows() <<"   "  <<numCols() <<"\n\n";
	
	    in >>tempx1>>tempy1;
	       if(tempx1 != 4 && tempy1!= 3){
	       
	          cout <<fileName<<" Doesnot have rectangle"<<endl;
		  return;
	       }
	    
	    in >>tempx1>>tempy1>>d;
	    
	    x1 = abs(tempx1);
	    y1 = abs(tempy1);
	    
	    in >>tempx1>>tempy1>>d;
	    
	    x2 = abs(tempx1);
	    y2 = abs(tempy1);
	    
   	    in >>tempx1>>tempy1>>d;
	    
	    x3 = abs(tempx1);
	    y3 = abs(tempy1);
	    
    	    in >>tempx1>>tempy1>>d;
	    
	    x4 = abs(tempx1);
	    y4 = abs(tempy1);

            in.close();

}


Rectangle::~Rectangle(){

}


bool Rectangle::draw(){

  drawLine(x1,y1,x2,y2);
  drawLine(x1,y1,x4,y4);
  drawLine(x2,y2,x3,y3);
  drawLine(x3,y3,x4,y4);
  
  
return true;
}

bool Rectangle::draw(const char *fileName){



      ifstream in(fileName);

      	int tempx1,tempy1;
	if(!in)
	{
	    cout <<"\n unable to open file : " <<fileName;
	     return false;	
	}
	
	//out <<numRows() <<"   "  <<numCols() <<"\n\n";
	
	    in >>tempx1>>tempy1;
	       if(tempx1 != 4 && tempy1!= 2){
	       
	          cout <<fileName<<" Doesnot have rectangle"<<endl;
		  return false;
	       }
	    
	    in >>tempx1>>tempy1;
	    
	    x1 = abs(tempx1);
	    y1 = abs(tempy1);
	    cout <<"From File Data : " <<x1<<"  "<<y1<<endl;
	    in >>tempx1>>tempy1;
	    
	    x2 = abs(tempx1);
	    y2 = abs(tempy1);
	    
	    cout <<"From File Data : " <<x2<<"  "<<y2<<endl;
   	    in >>tempx1>>tempy1;
	    
	    x3 = abs(tempx1);
	    y3 = abs(tempy1);
	    
	    cout <<"From File Data : " <<x3<<"  "<<y3<<endl;
    	    in >>tempx1>>tempy1;
	    
	    x4 = abs(tempx1);
	    y4 = abs(tempy1);

	    cout <<"From File Data : " <<x4<<"  "<<y4<<endl;
            in.close();

	    draw();
  return true;
}



bool Rectangle::draw(const Matrix &T){


   x1 =(int) T[0][0];
   y1 =(int) T[0][1];
   
   x2 =(int) T[1][0];
   y2 =(int) T[1][1];
   
   x3 =(int) T[2][0];
   y3 =(int) T[2][1];

   x4 =(int) T[3][0];
   y4 =(int) T[3][1];
   
   draw();

}
bool Rectangle::save(const char *fileName){

 return 1;
}

bool Rectangle::fill(){

//  XFillRectangle(show->display, show->win, show->gc, x1, x2, y1, y4);

 return 1;
}

